package top.hzy520.order.handler;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 16:29 2018/6/30
 */
@Configuration
public class OrderKeyExpiredHandler {
    @Bean
    public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory redisConnectionFactory){
        RedisMessageListenerContainer listenerContainer=new RedisMessageListenerContainer();
        listenerContainer.setConnectionFactory(redisConnectionFactory);
        listenerContainer.addMessageListener((message, listener)-> {
            //处理order订单过期
            System.out.println("过期时间创建成功"+new String(message.getBody()));
        },new PatternTopic("__keyevent@*__:expired"));
        return listenerContainer;
    }
}
